package myProject.gwt.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Widget;

public class Keyboard extends AbstractKeyboard {
	
	Grid grid = new Grid(5, 5);
	
	
	public Keyboard() {
		super();
		initWidget(grid);
		
		addButton(new Button("7"), 1, 1);
		addButton(new Button("8"), 1, 2);
		addButton(new Button("9"), 1, 3);
		addButton(new Button("4"), 2, 1);
		addButton(new Button("5"), 2, 2);
		addButton(new Button("6"), 2, 3);
		addButton(new Button("1"), 3, 1);
		addButton(new Button("2"), 3, 2);
		addButton(new Button("3"), 3, 3);
		addButton(new Button("0"), 4, 1);
	}
	
	protected void addButton(final Button button, int row, int col){
		setWidget(button, row, col);
		button.addClickHandler(new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				raiseKeyPressed(button.getText().charAt(0));
			}			
		});
	}
	
	public void setWidget(Widget widget, int row, int col){		
		grid.setWidget(row, col, widget);
	}
	
	
}
